package com.sx.gongzhong.adapter;

import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sx.gongzhong.R;
import com.sx.gongzhong.model.WebListItemBean;
import com.sx.gongzhong.net.ServiceFactory;
import com.sx.gongzhong.utils.BaseUtil;

import java.util.List;

/**便民公告 办事指南 平安宣传
 * Created by admin on 2018/1/3.
 */

public class WebListAdapter extends BaseQuickAdapter<WebListItemBean,BaseViewHolder> {

    private Context context;

    public WebListAdapter(Context context, @LayoutRes int layoutResId, @Nullable List<WebListItemBean> data) {
        super(layoutResId, data);
        this.context=context;
    }

    @Override
    protected void convert(BaseViewHolder helper, final WebListItemBean item) {
        helper.setText(R.id.tv_title,item.title);
        helper.setText(R.id.tv_content,item.content.replace("&nbsp;"," "));
        helper.setText(R.id.tv_readTimes,item.readTimes+"");
        helper.setText(R.id.tv_issued,item.issued);
        helper.setText(R.id.tv_releaseTime,item.releaseTime);
        ImageView imageView = helper.getView(R.id.iv_img);
        if (!BaseUtil.isEmpty(item.contentImgUrl)){
            imageView.setVisibility(View.VISIBLE);
            Glide.with(context).load(ServiceFactory.getUrl(item.contentImgUrl))
                    .apply(new RequestOptions().centerCrop().
                            placeholder(R.mipmap.img_fail).error(R.mipmap.img_fail))
                    .into(imageView);
        }else {
            imageView.setVisibility(View.GONE);
        }
    }
}
